/**
 * 招聘渠道
 */
import React from 'react';
import { Select } from 'antd';
import { useRequest } from '@/hooks';
import { getChannelListWithoutTalent } from '../../Setting/service';

const SelectChannel = React.forwardRef(({ value, onChange, ...rest }, ref) => {
    const { data = {} } = useRequest(getChannelListWithoutTalent);

    const options = React.useMemo(() => data?.data || [], [data]);

    const finalValue = typeof value === 'number' ? String(value) : value;

    return (
        <Select
            ref={ref}
            value={finalValue}
            onChange={(_value, item = {}) => {
                const { props = {} } = item;
                const { children } = props;
                onChange(_value, children);
            }}
            placeholder="请选择"
            optionFilterProp="children"
            filterOption={(input, option) => option.props.children.indexOf(input) >= 0}
            notFoundContent={null}
            showSearch
            allowClear
            {...rest}
        >
            {options.map(item => (
                <Select.Option key={item.channelCode} value={item.channelCode}>
                    {item.channelName}
                </Select.Option>
            ))}
        </Select>
    );
});

export default SelectChannel;
